package com.shopoo.behavior.mobile;

import com.shopoo.behavior.api.ReadService;
import com.shopoo.behavior.dto.cqe.BehaviorReadReadCmd;
import com.szmengran.cola.base.utils.RequestUtils;
import com.szmengran.cola.dto.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 阅读记录服务
 * @Package com.szmengran.behavior.controller
 * @CreateTime Mar 4, 2019 2:12:26 PM
 * @Author <a href="mailto:android_li@sina.cn">Joe</a>
 */
@Tag(name = "阅读记录服务API")
@RestController
@RequestMapping(path = "/read", produces = { "application/json" })
public class ReadController {

    @Resource
    private ReadService readService;

    /**
     * 增加阅读量
     * 
     * @param behaviorReadReadCmd
     * @return
     * @author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @Operation(summary = "增加阅读量")
    @PostMapping
    public Response addRead(
            @RequestBody @Parameter(name = "阅读量实体对象", description = "传入json格式", required = true) BehaviorReadReadCmd behaviorReadReadCmd,
            HttpServletRequest request) {

        String ip = RequestUtils.getRequestRealIp(request);
        behaviorReadReadCmd.setIp(ip);
        return readService.readCount(behaviorReadReadCmd);
    }
}
